package com.Trainer;

import com.Trainer.DifficultInterface.SelDifficultInterface;
import com.Trainer.FirstInterface.IndexInterface;
import com.Trainer.TestInterface.TestInterface;
import com.Trainer.TrainerInterface.TrainerInterface;
import javax.swing.*;
import java.awt.*;

public class myTrainer extends JFrame {
    //属性
    int width =920 ;
    int height = 560;
    String time="0";
    Container container = this.getContentPane();
    TrainerInterface trainerInterface = new TrainerInterface(width,height);
    IndexInterface indexInterface = new IndexInterface(width,height);
    TestInterface testInterface = new TestInterface(width,height);
    SelDifficultInterface difficultInterface=new SelDifficultInterface(width,height);
    //构造器
    public myTrainer(String title){
        super(title);
        setVisible(true);
        setBounds(300,300,920,560);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }

    //方法
    public void init(){
        //布局
        container.setLayout(null);
        container.add(indexInterface);
        container.add(trainerInterface);
        container.add(testInterface);
        container.add(difficultInterface);
        trainerInterface.setVisible(false);
        testInterface.setVisible(false);
        difficultInterface.setVisible(false);

        //事件
        indexInterface.getTrainerBtn().addActionListener((e)->{
            indexInterface.setVisible(false);
            trainerInterface.setVisible(true);
        });

        indexInterface.getTextBtn().addActionListener((e)->{
            indexInterface.setVisible(false);
            testInterface.setVisible(false);
            difficultInterface.setVisible(true);
            testInterface.reset(time);
        });

        difficultInterface.getReturnButton().addActionListener((e)->{
            difficultInterface.setVisible(false);
            indexInterface.setVisible(true);
        });

        difficultInterface.getEasyButton().addActionListener((e)->{
            time="420";
            testInterface.reset(time);
            difficultInterface.setVisible(false);
            testInterface.setVisible(true);
        });

        difficultInterface.getMiddleButton().addActionListener((e)->{
            time="300";
            testInterface.reset(time);
            difficultInterface.setVisible(false);
            testInterface.setVisible(true);
        });

        difficultInterface.getDiffButton().addActionListener((e)->{
            time="180";
            testInterface.reset(time);
            difficultInterface.setVisible(false);
            testInterface.setVisible(true);
        });

        trainerInterface.getBackBtn().addActionListener((e)->{
            indexInterface.setVisible(true);
            trainerInterface.setVisible(false);
        });

        testInterface.getBackBtn().addActionListener((e)->{
            indexInterface.setVisible(true);
            testInterface.setVisible(false);
            testInterface.reset(time);
            testInterface.resetLayout();
            testInterface.getTime().stop();
        });

        testInterface.getEvaluateBackBtn().addActionListener((e)->{
            indexInterface.setVisible(true);
            testInterface.setVisible(false);
            testInterface.reset(time);
            testInterface.resetLayout();
        });
    }

}
